<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>设备借出审核</title>
    <!--freemarker引入模板文件 使用相对路径来引入的-->
    <#include "../../common/link.ftl" >
    <link type="text/css" rel="stylesheet" href="/js/plugins/uploadifive/uploadifive.css" />
    <script type="text/javascript" src="/js/plugins/uploadifive/jquery.uploadifive.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/js/plugins/bootstrap-select/bootstrap-select.css"/>
    <script src="/js/plugins/bootstrap-select/bootstrap-select.js"></script>
    <script>
        $(function () {
            //新增/编辑按钮点击事件
            $(".btn-input").click(function () {
                //清除模态框的数据
                //数据复原
                $("#editForm").clearForm(true);
                $("#editForm input").val('');
                $('#associationId').selectpicker('val', '');
                $(".modal-title").html("设备新增");
                //$("#editForm")[0].reset(); //不能清除隐藏域
                //获取事件源绑定的数据 使用data方法可以很方便获取data-*开头的属性的数据
                var json = $(this).data("json");
                console.log(json)
                if(json){ //json有数据代表是编辑
                    $(".modal-title").html("设备编辑");
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='name']").val(json.name);
                    $("#editForm input[name='deviceNumber']").val(json.deviceNumber);
                    $("#editForm input[name='nowNumber']").val(json.nowNumber);
                    $("#editForm input[name='imgUrl']").val(json.imgUrl);
                    $("#editForm img[id='coverUrl']").val(json.imgUrl);
                    $("#editForm textarea[name='sn']").val(json.sn);
                }

                //打开模态框
                $("#myModal").modal('show');
            })

            // 申请借出
            $(".leadBtn").click(function () {
                //清除模态框的数据
                //数据复原
                $("#editForm1").clearForm(true);
                $('#associationId').selectpicker('val', '');
                //获取事件源绑定的数据 使用data方法可以很方便获取data-*开头的属性的数据
                var json = $(this).data("json");
                console.log(json)
                if(json){ //json有数据代表是编辑
                    $(".modal-title1").html("借出申请");
                    $("#editForm1 input[name='deviceId']").val(json.id);
                    $("#editForm1 input[name='name']").val(json.name);
                    $("#editForm1 input[name='deviceNumber']").val(json.deviceNumber);
                    $("#editForm1 input[name='nowNumber']").val(json.nowNumber);
                    $("#editForm1 input[name='imgUrl']").val(json.imgUrl);
                    $("#editForm1 img[id='coverUrl2']").attr("src",json.imgUrl);
                }

                //打开模态框
                $("#lendModal").modal('show');
            })

            // 主办方
            $.get("/association/listAsso", {}, function (data) {
                var html = '';
                var associations = data.data;
                $.each(associations, function (index, item) {
                    html += '<option value="' + item.id + '">'+item.username+'</option>'
                })
                $("#associationId").html(html);

                $('#associationId').selectpicker('refresh'); //刷新组件
            })

            // 图片上传
            $('.imgBtn').uploadifive({
                'auto' : true,    // 自动发送图片上传请求
                'uploadScript' : '/uploadImg.do',  // 图片上传的请求路径
                buttonClass:"btn-link",    // 点击按钮的class
                'fileObjName' : 'pic',   // 文件上传的参数名
                'buttonText' : '浏览...',
                'fileType' : 'image',  // 上传文件类型
                'multi' : false,    // 是否上传多个
                'fileSizeLimit'   : 5242880,  // 每次上传限制的文件大小
                'removeCompleted' : true, //取消上传完成提示
                'uploadLimit' : 1,  // 上传个数限制
                //'queueSizeLimit'  : 10,   // 文件上传区域大小的限制
                'overrideEvents': ['onDialogClose', 'onError'],    //onDialogClose 取消自带的错误提示
                'onUploadComplete' : function(file, data) {  // 回调函数
                    $("#coverUrl").attr("src" ,data);  // data 约定是json格式的格式地址
                    $("#imgUrl").val(data);

                },
                onFallback : function() {
                    $.messager.alert("温馨提示","该浏览器无法使用!");
                }
            });


            //保存：新增/编辑
            $(".btn-submit").click(function () {
                //使用jquery-form插件来提交异步表单(有表单时会使用该插件,写的代码比较少)
                $("#editForm").ajaxSubmit(handlerMessage)
            })

            //保存：申请借出
            $(".btn-submitLend").click(function () {
                //使用jquery-form插件来提交异步表单(有表单时会使用该插件,写的代码比较少)
                $("#editForm1").ajaxSubmit(function (data) {
                    if(data.code == 200){
                        $.messager.alert("温馨提示","已提交申请!2s后自动关闭。");
                        window.setTimeout(function () {
                            window.location.reload();
                        },2000)
                    }else{
                        $.messager.alert("温馨提示", data.msg);
                    }
                })
            })

            //删除按钮
            $(".btn-delete").click(function () {
                //获取当前点击的部门id
                var id = $(this).data('id');
                //提示确认框
                $.messager.confirm("警告","是否确认删除?",function () {
                    //发送ajax请求
                    $.get('/device/delete.do',{id:id},handlerMessage)
                })
            })


        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <!--页面头部-->
    <#include "../../common/navbar.ftl" >
    <!--菜单回显 声明变量设置值-->
    <#assign currentMenu="deviceAdmin"/>
    <!--菜单-->
    <#include "../../common/menu.ftl" >
    <div class="content-wrapper">
        <section class="content-header">
            <h1>设备信息列表</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/device/list.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label for="keyword">关键字：</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}" placeholder="请输入设备名称">
                    </div>
                    &nbsp;
                    <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>
                    <a href="JavaScript:;" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">

                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>图片</th>
                            <th>设备名称</th>
                            <th>总数量</th>
                            <th>现存数量</th>
                            <th>备注</th>
                            <th>申请借用</th>
                            <th>操作</th>
                        </tr>
                            <#list page.list as device>
                                  <tr>
                                      <!--freemarker 如果取值时是空值 会报错-->
                                      <td>${device_index+1}</td>
                                      <td><img src="${(device.imgUrl)!'/images/default.jpg'}" width="50px"></td>
                                      <td>${device.name!}</td>
                                      <td>${device.deviceNumber!}</td>
                                      <td>${device.nowNumber!}</td>
                                      <td>${device.sn!}</td>
                                      <td>
                                          <#if ((device.nowNumber)!) <= 0 >
                                              库存不足
                                          <#else>
                                              <a class="btn btn-success btn-xs leadBtn" href="javascript:;" data-json='${device.jsonString}'>
                                                  <span class="glyphicon glyphicon-minus-sign"></span> 申请借用
                                              </a>
                                          </#if>
                                      </td>
                                      <td>
                                          <!-- 使用data-*绑定自定义数据-->
                                          <a href="JavaScript:;"
                                             class="btn btn-info btn-xs btn-input"
                                             data-json='${device.jsonString}' >
                                              <span class="glyphicon glyphicon-pencil"></span> 编辑
                                          </a>
                                          <a href="JavaScript:;"
                                             class="btn btn-danger btn-xs btn-delete"
                                             data-id='${device.id}'>
                                              <span class="glyphicon glyphicon-trash"></span> 删除
                                          </a>
                                      </td>
                                  </tr>
                            </#list>
                    </table>
                    <!--分页-->
                    <#include "../../common/page.ftl">
                </div>
            </div>
        </section>
    </div>
     <#include "../../common/footer.ftl">
</div>

<!-- 大图显示 -->
<div id="ShowImage_Form" class="modal fade" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body" >
            </div>
        </div>
    </div>
</div>


<script>
    $("table img").click(function(){
        var src = $(this).attr("src");
        $("#ShowImage_Form .modal-body").html("<img src='"+src+"' class='carousel-inner img-responsive img-rounded' />");
        $("#ShowImage_Form").modal('show');
    })
</script>

<!-- Modal模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">设备新增</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/device/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">设备名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name"
                                   placeholder="请输入设备名称">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="deviceNumber" class="col-sm-3 control-label">设备总数量：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="deviceNumber" name="deviceNumber"
                                   placeholder="请输入设备总数量">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="nowNumber" class="col-sm-3 control-label">设备现存数量：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="nowNumber" name="nowNumber"
                                   placeholder="请输入设备现存数量">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="imgUrl" class="col-sm-3 control-label">图片：</label>
                        <div class="col-sm-6">
                            <input type="hidden"  class="form-control" name="imgUrl" id="imgUrl" />
                            <img src="/images/default.jpg" width="100px" id="coverUrl">
                            <button type="button" class="imgBtn">浏览</button>
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">备注：</label>
                        <div class="col-sm-6">
                            <textarea class="form-control" name="sn" id="sn"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="lendModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title1" id="lendModalLabel">设备借出申请</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/deviceRecord/saveLend.do" method="post" id="editForm1">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="imgUrl" class="col-sm-3 control-label">图片：</label>
                        <div class="col-sm-6">
                            <input type="hidden"  class="form-control"  name="imgUrl">
                            <img src="/images/default.jpg" width="100px" id="coverUrl2">
                        </div>
                    </div>

                    <input type="hidden" name="deviceId">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">设备名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name"
                                   placeholder="请输入设备名称" readonly>
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="deviceNumber" class="col-sm-3 control-label">设备总数量：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="deviceNumber" name="deviceNumber"
                                   placeholder="请输入设备总数量" readonly>
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="nowNumber" class="col-sm-3 control-label">设备现存数量：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="nowNumber" name="nowNumber"
                                   placeholder="请输入设备现存数量" readonly>
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="number" class="col-sm-3 control-label">借出数量：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="number" name="number"
                                   placeholder="请输入借出数量">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="associationId" class="col-sm-3 control-label">社团名称：</label>
                        <div class="col-sm-6">
                            <select class="form-control selectpicker" id="associationId" name="associationId" data-live-search="true" title="请选择关联的社团">

                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="site" class="col-sm-3 control-label">负责人：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="dutyName" name="dutyName" placeholder="请输入负责人姓名">
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="site" class="col-sm-3 control-label">联系方式：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="mobile" name="mobile" placeholder="请输入负责人电话">
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="reason" class="col-sm-3 control-label">申请理由：</label>
                        <div class="col-sm-6">
                            <textarea class="form-control" name="reason" id="reason"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submitLend">申请借出</button>
            </div>
        </div>
    </div>
</div>

</body>
</html>
